#include "btform.h"
#include "ui_btform.h"


BtForm::BtForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::BtForm)
{
    ui->setupUi(this);


    setAnimation();   
}

BtForm::~BtForm()
{
    delete ui;
}

void BtForm::section(QString btIcon, QString btText, int pageId)
{
    ui->btIcon->setPixmap(QPixmap(btIcon));
    ui->btText->setText(btText);
    this->pageId = pageId;

}

int BtForm::getPageId() const
{
    return this->pageId;
}

void BtForm::clearBackground()
{
    // 清除上⼀个按钮点击的背景效果,恢复之前的样式
    ui->btStyle->setStyleSheet("#btStyle:hover{ background-color:#D8D8D8;}");

}

void BtForm::hideAnimal()
{
    ui->lineBox->setStyleSheet("");  // 显示控件
}

void BtForm::setBackgroundColor()
{
    ui->btStyle->setStyleSheet("#btStyle {background-color:rgba(0, 204, 101,0.5);}");

    ui->btStyle->update();
}


void BtForm::mousePressEvent(QMouseEvent *event)
{
    // 告诉编译器不要触发警告
    (void)event;
    // 鼠标点击之后，背景变为绿色
    ui->btStyle->setStyleSheet("#btStyle {background-color:rgba(0, 204, 101,0.5);}");

    emit btClick(pageId); // 发送鼠标点击信号和当前btfrom控件对应的pageId
}

// 参数： 要监视的类型，鼠标事件


void BtForm::setAnimation()
{
    // 设置line1的动画效果
    line1Animal = new QPropertyAnimation(ui->line1, "geometry", this);
    line1Animal->setDuration(1500);
    line1Animal->setKeyValueAt(0, QRect(0, 29, 2, 0));
    line1Animal->setKeyValueAt(0.5, QRect(0, 6, 2, 23));
    line1Animal->setKeyValueAt(1, QRect(0, 29, 2, 0));
    line1Animal->setLoopCount(-1);
    line1Animal->start();

    // 设置line2的动画效果
    line2Animal = new QPropertyAnimation(ui->line2, "geometry", this);
    line2Animal->setDuration(1600);
    line2Animal->setKeyValueAt(0, QRect(7, 29, 2, 0));
    line2Animal->setKeyValueAt(0.5, QRect(7, 6, 2, 23));
    line2Animal->setKeyValueAt(1, QRect(7, 29, 2, 0));
    line2Animal->setLoopCount(-1);
    line2Animal->start();

    // 设置line3的动画效果
    line3Animal = new QPropertyAnimation(ui->line3, "geometry", this);
    line3Animal->setDuration(1700);
    line3Animal->setKeyValueAt(0, QRect(14, 29, 2, 0));
    line3Animal->setKeyValueAt(0.5, QRect(14, 6, 2, 23));
    line3Animal->setKeyValueAt(1, QRect(14, 29, 2, 0));
    line3Animal->setLoopCount(-1);
    line3Animal->start();

    // 设置line4的动画效果
    line4Animal = new QPropertyAnimation(ui->line4, "geometry", this);
    line4Animal->setDuration(1800);
    line4Animal->setKeyValueAt(0, QRect(21, 29, 2, 0));
    line4Animal->setKeyValueAt(0.5, QRect(21, 6, 2, 23));
    line4Animal->setKeyValueAt(1, QRect(21, 29, 2, 0));
    line4Animal->setLoopCount(-1);
    line4Animal->start();
}
